package edu.gatech.gui;

import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;

import edu.gatech.datastorage.Gender;
import edu.gatech.presenters.NursePresenter;
import edu.gatech.userclasses.Nurse;

public class NursePanel {
	private static JTextField txtPatientName;
	private static JTextField txtPatientPassword;
	private static JTextField txtAge;
	private static JTextField txtPhoneNumber;
	private static JTextField txtAddress;
	private static JTextField txtPharmacy;
	private static JTextField txtInsurance;
	private static JTextField txtDateOfBirth;
	private static JButton btnCreatePatient;
	private static JTextField txtMedications;
	private static JTextField txtPatientName_1;
	private static JButton btnCreateTreatmentRecord;
	private static JButton btnViewAppointments;
	private static JTextField txtPatientName_2;
	private static JButton btnSearch;
	private static JTextField txtAllergies;
	private static JComboBox comboBox;
	private Nurse currentNurse;
	private JPanel panel;
	private JPanel panel_2;
	private NursePresenter presenter;
	public NursePanel(Nurse curNurse){
		currentNurse = curNurse;
		JFrame nurse = new JFrame("Nurse Panel");
		JPanel nursePanel = new JPanel();
		
		nurse.setSize(640,480);
		
		nurse.getContentPane().add(nursePanel, BorderLayout.CENTER);
		nursePanel.setLayout(null);
		
		Gender[]  gender = {Gender.MALE, Gender.FEMALE};
		
		txtPatientName_1 = new JTextField();
		txtPatientName_1.addMouseListener(new MouseAdapter() { 
	          public void mousePressed(MouseEvent me) { 
	            txtPatientName_1.setText(""); 
	          } 
	     }); 
		txtPatientName_1.setFont(new Font("Arial", Font.PLAIN, 10));
		txtPatientName_1.setBounds(204, 81, 218, 21);
		nursePanel.add(txtPatientName_1);
		
		txtPatientName_1.setColumns(10);
		
		btnViewAppointments = new JButton("View Appointments");
		btnViewAppointments.setFont(new Font("Arial", Font.PLAIN, 9));
		btnViewAppointments.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				presenter = new NursePresenter(currentNurse);
				presenter.viewAppointment(txtPatientName_1.getText());
			}
		});
		btnViewAppointments.setBounds(280, 113, 142, 23);
		nursePanel.add(btnViewAppointments);
		
		btnCreateTreatmentRecord = new JButton("Treatment Record");
		btnCreateTreatmentRecord.setFont(new Font("Arial", Font.PLAIN, 10));
		btnCreateTreatmentRecord.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				presenter = new NursePresenter(currentNurse);
				presenter.createTreatmentRecord(txtPatientName_1.getText());
			}
		});
		btnCreateTreatmentRecord.setBounds(125, 113, 142, 23);
		nursePanel.add(btnCreateTreatmentRecord);
		
		txtPhoneNumber = new JTextField();
		txtPhoneNumber.addMouseListener(new MouseAdapter() { 
	          public void mousePressed(MouseEvent me) { 
	            txtPhoneNumber.setText(""); 
	          } 
	     }); 
		txtPhoneNumber.setBounds(123, 309, 166, 21);
		nursePanel.add(txtPhoneNumber);
		txtPhoneNumber.setFont(new Font("Arial", Font.PLAIN, 10));
		txtPhoneNumber.setText("Phone Number");
		txtPhoneNumber.setColumns(10);
		
		txtAddress = new JTextField();
		txtAddress.addMouseListener(new MouseAdapter() { 
	          public void mousePressed(MouseEvent me) { 
	            txtAddress.setText(""); 
	          } 
	     }); 
		txtAddress.setBounds(375, 185, 166, 21);
		nursePanel.add(txtAddress);
		txtAddress.setFont(new Font("Arial", Font.PLAIN, 10));
		txtAddress.setText("Address");
		txtAddress.setColumns(10);
		
		txtPharmacy = new JTextField();
		txtPharmacy.addMouseListener(new MouseAdapter() { 
	          public void mousePressed(MouseEvent me) { 
	            txtPharmacy.setText(""); 
	          } 
	     }); 
		txtPharmacy.setBounds(375, 309, 166, 21);
		nursePanel.add(txtPharmacy);
		txtPharmacy.setFont(new Font("Arial", Font.PLAIN, 10));
		txtPharmacy.setText("Pharmacy");
		txtPharmacy.setColumns(10);
		
		txtInsurance = new JTextField();
		txtInsurance.addMouseListener(new MouseAdapter() { 
	          public void mousePressed(MouseEvent me) { 
	            txtInsurance.setText(""); 
	          } 
	     }); 
		txtInsurance.setBounds(375, 216, 166, 21);
		nursePanel.add(txtInsurance);
		txtInsurance.setFont(new Font("Arial", Font.PLAIN, 10));
		txtInsurance.setText("Insurance");
		txtInsurance.setColumns(10);
		
		txtMedications = new JTextField();
		txtMedications.addMouseListener(new MouseAdapter() { 
	          public void mousePressed(MouseEvent me) { 
	            txtMedications.setText(""); 
	          } 
	     }); 
		txtMedications.setBounds(375, 277, 166, 21);
		nursePanel.add(txtMedications);
		txtMedications.setFont(new Font("Arial", Font.PLAIN, 10));
		txtMedications.setText("Medications");
		txtMedications.setColumns(10);
		
		txtAllergies = new JTextField();
		txtAllergies.addMouseListener(new MouseAdapter() { 
	          public void mousePressed(MouseEvent me) { 
	            txtAllergies.setText(""); 
	          } 
	     }); 
		txtAllergies.setBounds(375, 247, 166, 21);
		nursePanel.add(txtAllergies);
		txtAllergies.setFont(new Font("Arial", Font.PLAIN, 10));
		txtAllergies.setText("Allergies");
		txtAllergies.setColumns(10);
		
		btnCreatePatient = new JButton("Create Patient");
		btnCreatePatient.setBounds(304, 340, 123, 23);
		nursePanel.add(btnCreatePatient);
		btnCreatePatient.setFont(new Font("Arial", Font.PLAIN, 10));
		
		comboBox = new JComboBox(gender);
		comboBox.setBounds(123, 341, 166, 21);
		nursePanel.add(comboBox);
		comboBox.setFont(new Font("Arial", Font.PLAIN, 10));
		
		txtPatientName = new JTextField();
		txtPatientName.addMouseListener(new MouseAdapter() { 
	          public void mousePressed(MouseEvent me) { 
	            txtPatientName.setText(""); 
	          } 
	     }); 
		txtPatientName.setBounds(123, 185, 166, 21);
		nursePanel.add(txtPatientName);
		txtPatientName.setFont(new Font("Arial", Font.PLAIN, 10));
		txtPatientName.setText("\r\n");
		txtPatientName.setColumns(15);
		
		txtPatientPassword = new JTextField();
		txtPatientPassword.addMouseListener(new MouseAdapter() { 
	          public void mousePressed(MouseEvent me) { 
	            txtPatientPassword.setText(""); 
	          } 
	     }); 
		txtPatientPassword.setBounds(123, 216, 166, 21);
		nursePanel.add(txtPatientPassword);
		txtPatientPassword.setFont(new Font("Arial", Font.PLAIN, 10));
		txtPatientPassword.setText("\r\n");
		txtPatientPassword.setColumns(15);
		
		txtDateOfBirth = new JTextField();
		txtDateOfBirth.addMouseListener(new MouseAdapter() { 
	          public void mousePressed(MouseEvent me) { 
	            txtDateOfBirth.setText(""); 
	          } 
	     }); 
		txtDateOfBirth.setBounds(123, 277, 166, 21);
		nursePanel.add(txtDateOfBirth);
		txtDateOfBirth.setFont(new Font("Arial", Font.PLAIN, 10));
		txtDateOfBirth.setText("Date of Birth");
		txtDateOfBirth.setColumns(10);
		
		txtAge = new JTextField();
		txtAge.addMouseListener(new MouseAdapter() { 
	          public void mousePressed(MouseEvent me) { 
	            txtAge.setText(""); 
	          } 
	     }); 
		txtAge.setBounds(123, 247, 166, 21);
		nursePanel.add(txtAge);
		txtAge.setFont(new Font("Arial", Font.PLAIN, 10));
		txtAge.setText("Age");
		txtAge.setColumns(10);
		
		panel = new JPanel();
		panel.setBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null));
		panel.setBounds(386, 11, 188, 34);
		nursePanel.add(panel);
		
		txtPatientName_2 = new JTextField();
		txtPatientName_2.addMouseListener(new MouseAdapter() { 
	          public void mousePressed(MouseEvent me) { 
	            txtPatientName_2.setText(""); 
	          } 
	     }); 
		panel.add(txtPatientName_2);
		txtPatientName_2.setFont(new Font("Arial", Font.PLAIN, 10));
		txtPatientName_2.setText("Patient Name");
		txtPatientName_2.setColumns(10);
		
		btnSearch = new JButton("Search");
		panel.add(btnSearch);
		btnSearch.setFont(new Font("Arial", Font.PLAIN, 10));
		
		JLabel lblPatientName = new JLabel("Patient Name:");
		lblPatientName.setFont(new Font("Arial", Font.PLAIN, 10));
		lblPatientName.setBounds(125, 84, 78, 14);
		nursePanel.add(lblPatientName);
		
		panel_2 = new JPanel();
		panel_2.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null), "Records", TitledBorder.LEADING, TitledBorder.TOP, null, UIManager.getColor("Button.darkShadow")));
		panel_2.setBounds(85, 58, 374, 94);
		nursePanel.add(panel_2);
		
		JLabel lblPatientName_1 = new JLabel("Patient Name:");
		lblPatientName_1.setFont(new Font("Arial", Font.PLAIN, 10));
		lblPatientName_1.setBounds(44, 188, 79, 14);
		nursePanel.add(lblPatientName_1);
		
		JLabel lblPatientPassword = new JLabel("Patient Password:");
		lblPatientPassword.setFont(new Font("Arial", Font.PLAIN, 10));
		lblPatientPassword.setBounds(34, 219, 99, 14);
		nursePanel.add(lblPatientPassword);
		
		JButton btnCancel = new JButton("Cancel");
		btnCancel.setFont(new Font("Arial", Font.PLAIN, 10));
		btnCancel.setBounds(437, 340, 104, 23);
		nursePanel.add(btnCancel);
		
		JLabel lblAddress = new JLabel("Address:");
		lblAddress.setFont(new Font("Arial", Font.PLAIN, 10));
		lblAddress.setBounds(319, 188, 46, 14);
		nursePanel.add(lblAddress);
		
		JLabel lblInsurancel = new JLabel("Insurance:\r\n");
		lblInsurancel.setFont(new Font("Arial", Font.PLAIN, 10));
		lblInsurancel.setBounds(314, 219, 61, 14);
		nursePanel.add(lblInsurancel);
		
		JLabel lblAllergies = new JLabel("Allergies:");
		lblAllergies.setFont(new Font("Arial", Font.PLAIN, 10));
		lblAllergies.setBounds(319, 250, 46, 14);
		nursePanel.add(lblAllergies);
		
		JLabel lblMedications = new JLabel("Medications:");
		lblMedications.setFont(new Font("Arial", Font.PLAIN, 10));
		lblMedications.setBounds(304, 280, 61, 14);
		nursePanel.add(lblMedications);
		
		JLabel lblPharmacy = new JLabel("Pharmacy:");
		lblPharmacy.setFont(new Font("Arial", Font.PLAIN, 10));
		lblPharmacy.setBounds(314, 312, 61, 14);
		nursePanel.add(lblPharmacy);
		
		JLabel lblAge = new JLabel("Age:");
		lblAge.setFont(new Font("Arial", Font.PLAIN, 10));
		lblAge.setBounds(83, 250, 30, 14);
		nursePanel.add(lblAge);
		
		JLabel lblDateOfBirth = new JLabel("Date of Birth:");
		lblDateOfBirth.setFont(new Font("Arial", Font.PLAIN, 10));
		lblDateOfBirth.setBounds(43, 280, 70, 14);
		nursePanel.add(lblDateOfBirth);
		
		JLabel lblPhoneNumber = new JLabel("Phone Number:");
		lblPhoneNumber.setFont(new Font("Arial", Font.PLAIN, 10));
		lblPhoneNumber.setBounds(34, 312, 79, 14);
		nursePanel.add(lblPhoneNumber);
		
		JLabel lblSex = new JLabel("Sex:");
		lblSex.setFont(new Font("Arial", Font.PLAIN, 10));
		lblSex.setBounds(83, 344, 30, 14);
		nursePanel.add(lblSex);
		
		JPanel panel_1 = new JPanel();
		panel_1.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null), "Create Patient", TitledBorder.LEADING, TitledBorder.TOP, null, UIManager.getColor("Button.darkShadow")));
		panel_1.setBounds(10, 163, 564, 218);
		nursePanel.add(panel_1);
		btnSearch.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
					presenter = new NursePresenter(currentNurse);
					presenter.search(txtPatientName_2.getText());
			}
		});
		btnCreatePatient.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				presenter = new NursePresenter(currentNurse);
				presenter.createPatient(txtPatientName.getText(), txtMedications.getText(), txtAllergies.getText(),
						txtPatientPassword.getText(), txtAge.getText(), (Gender)comboBox.getSelectedItem(), 
						txtPhoneNumber.getText(), txtAddress.getText(), txtPharmacy.getText(), txtInsurance.getText(), 
						txtDateOfBirth.getText());
			}
		});
		
		MenuBar menuBar = new MenuBar(nurse);
		
		nurse.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		nurse.setSize(600,480);
		nurse.setTitle("Nurse Panel");
		nurse.setLocationRelativeTo(null);  
		nurse.setVisible(true);
	}
}
